package org.fuxian.service.impl;

import org.fuxian.dao.MySortMapper;
import org.fuxian.domain.MySort;
import org.fuxian.service.IMySortService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MySortServiceImpl implements IMySortService {

    @Autowired
    private MySortMapper mysortMapper;
    @Override
    public MySort findById(int sid) {
        return mysortMapper.findById(sid);
    }
    @Override
    public MySort findSortByName(String sname) {
        return mysortMapper.findByName(sname);
    }
    @Override
    public int add(String sname) {
        return mysortMapper.add(sname);
    }
    @Override
    public int update(String sname, int sid) {
        return mysortMapper.update(sname,sid);
    }
    @Override
    public List<MySort> findAll() {
        return mysortMapper.findAll();
    }
    @Override
    public int delete(int sid) {
        int count = 0;
        try {
            count = mysortMapper.delete(sid);
        } catch (Exception e) {
            //外键约束
            count = -1;
            e.printStackTrace();
            System.err.println(e.getMessage() + "\n" + "请先删除该类别的房屋");
        }
        return count;
    } }